package com.reizx.xocre.custom.wdj;

import android.app.AndroidAppHelper;
import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;

import com.reizx.xocre.custom.wdj.MySharedPreferencesImpl.WdjMySharedPreferencesImplConstructor;
import com.reizx.xocre.log.XCoreLogUtil;
import com.reizx.xocre.system.System.Fuck_getString;
import com.reizx.xocre.system.System.Fuck_putString;

import java.io.File;
import java.util.Map;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

/**
 * Created by admin on 2017/5/5.
 */

public class WdjTutorial {
    public static void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam){
        //获取context
        Context context = (Context) AndroidAppHelper.currentApplication();
        if (context != null){
            XCoreLogUtil.log("find context failed");
        }
//        Settings.System.putString(context.getContentResolver(), "mqBRboGZkQPcAkyk", "" );
//        Settings.System.putString(context.getContentResolver(), "dxCRMxhQkdGePGnp", "" );
//        Settings.System.putString(context.getContentResolver(), "6c709c11d2d46a7b", "" );
//        Settings.System.putString(context.getContentResolver(), "dd7893586a493dc3", "" );
//        Settings.System.putString(context.getContentResolver(), "58669b0e4dd2beb8", "" );
//        Settings.System.putString(context.getContentResolver(), "85d32f14e4edccf2", "" );
//        Settings.System.putString(context.getContentResolver(), "e5c06c338bfa3568", "" );
//        Settings.System.putString(context.getContentResolver(), "636f6d2e77616e646f756a69612e70686f656e697832dynamicreid\n", "" );
//        Settings.System.putString(context.getContentResolver(), "636f6d2e77616e646f756a69612e70686f656e697832dynamicrsid", "" );
//        Settings.System.putString(context.getContentResolver(), "time_12_24", "" );


        XCoreLogUtil.log("load...");
        XposedHelpers.findAndHookMethod(Settings.System.class, "putString", ContentResolver.class, String.class, String.class, new Fuck_putString());
        XposedHelpers.findAndHookMethod(Settings.System.class, "getString", ContentResolver.class, String.class, new Fuck_getString());
        //===========================================
        //custom 自定义函数
        Class<?> classMySharedPreferencesImpl = XposedHelpers.findClass("com.ta.utdid2.core.persistent.TransactionXMLFile.MySharedPreferencesImpl", loadPackageParam.classLoader);
        if (classMySharedPreferencesImpl != null){
            XCoreLogUtil.log("find class classMySharedPreferencesImpl success");
            XposedHelpers.findAndHookConstructor(classMySharedPreferencesImpl, File.class, int.class, Map.class, new WdjMySharedPreferencesImplConstructor());
        }

        //======================================
        //com.taobao.wireless.security.adapter.common.f->a(Context arg3_context, String arg4_key)函数hook
        Class<?> com_taobao_wireless_security_adapter_common_f = XposedHelpers.findClass("com.taobao.wireless.security.adapter.common.f", loadPackageParam.classLoader);
        XposedHelpers.findAndHookMethod(com_taobao_wireless_security_adapter_common_f, "a", Context.class, String.class, new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                super.beforeHookedMethod(param);

            }

            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                super.afterHookedMethod(param);
                XCoreLogUtil.log("com_taobao_wireless_security_adapter_common_f->a key : " + param.args[1] + "  result : " + param.getResult());
            }
        });
        XposedHelpers.findAndHookMethod(com_taobao_wireless_security_adapter_common_f, "b", Context.class, String.class, new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                super.beforeHookedMethod(param);

            }

            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                super.afterHookedMethod(param);
                XCoreLogUtil.log("com_taobao_wireless_security_adapter_common_f->b key : " + param.args[1] + "  result : " + param.getResult());
            }
        });
        //======================================
        Class<?> com_taobao_wireless_security_adapter_common_SPUtility2 = XposedHelpers.findClass("com.taobao.wireless.security.adapter.common.SPUtility2", loadPackageParam.classLoader);
        XposedHelpers.findAndHookMethod(com_taobao_wireless_security_adapter_common_SPUtility2, "readFromSPUnified", String.class, String.class,String.class, new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                super.beforeHookedMethod(param);

            }

            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                super.afterHookedMethod(param);
                XCoreLogUtil.log("com_taobao_wireless_security_adapter_common_SPUtility2 p0 : " + param.args[0] + "  p1 : " + param.args[1] + "  p2 : " + param.args[2] + "  result : " + param.getResult());
            }
        });
    }
}
